package cn.tedu.boot111.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileController {
    @RequestMapping("/appFile")
    public String appFile(MultipartFile addf) throws IOException {
        String fileName=addf.getOriginalFilename();
        String fileSuffix=fileName.substring(fileName.lastIndexOf("."));
        System.out.println(fileSuffix);
        fileName= UUID.randomUUID()+fileSuffix;
        File dirPush=new File("C:/files2");
        if (!dirPush.exists()){
            dirPush.mkdirs();
        }
        String filePush=dirPush+"/"+fileName;
        addf.transferTo(new File(filePush));
        return fileName;
    }

    @RequestMapping("/delete")
    public void delete(String fileName){
        String filePush="C:/files2/"+fileName;
        System.out.println(filePush);
        new File(filePush).delete();

    }
}
